﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace SoundServant.Controls
{
    /// <summary>
    /// Interaction logic for TouchLabel.xaml
    /// </summary>
    public partial class TouchBox : UserControl
    {
        private string text = "";
        private bool password = false;

        private string displayName = "";
        public string Text
        {
            get
            {
                return text;
            }
            set
            {
                text = value;
                Draw();

            }
        }
        public bool Password
        {
            get
            {
                return password;
            }
            set
            {
                password = value;
            }
        }
        public string DisplayName
        {
            get
            {
                return displayName;
            }
            set
            {
                displayName = value;
            }
        }

        public delegate void ValueChangedEventHandler(string _text);
        public event ValueChangedEventHandler ValueChanged;

        void Draw()
        {
            if (!password)
            {
                TextLabel.Content = Text;
            }
            else
            {
                string textToDisplay = "";
                for (int i = 0; i < text.Length; i++)
                {
                    textToDisplay += "*";
                }

                TextLabel.Content = textToDisplay;
            }
        }

        public TouchBox(string _text, string _name)
        {
            InitializeComponent();
            text = _text;
            Draw();
        }

        public TouchBox(string _text, string _name, bool _password)
        {
            InitializeComponent();
            text = _text;
            password = _password;
            Draw();
        }

        public TouchBox()
        {
            InitializeComponent();
        }

        private void Border_MouseDown(object sender, MouseButtonEventArgs e)
        {
            string newText = KeyboardEntryWindow.ShowKeyboard(text, displayName, password);
            text = newText;
            Draw();
            if (ValueChanged != null) ValueChanged(text);
        }
    }
}
